package com.jj.dao.impl;

import com.jj.dao.BaseDao;
import com.jj.dao.DepartmentDao;
import com.jj.entity.Department;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DepartmentDaoImpl extends BaseDao implements DepartmentDao {
    @Override
    public List<Department> getDepartment() {
        List<Department> list = new ArrayList<Department>();
        String sql = "select * from department";
        ResultSet rs = executeQuery(sql);
        if(rs != null) {
            try {
                while (rs.next()) {
                    Department department = new Department();
                    department.setId(rs.getInt("id"));
                    department.setDeptName(rs.getString("dept_name"));
                    department.setDescription(rs.getString("description"));
                    list.add(department);
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            } finally {
                closedAll(rs);
            }
        }
        return list;
    }
}
